package com.cjc.test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class test2 {
	public static void main(String[] args) {
		String time="2015/07/28";
		Date date=stringToDate(time, "yyyy/MM/dd");
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		System.out.println(calendar.get(Calendar.YEAR));
		System.out.println(calendar.get(Calendar.MONTH));
		System.out.println(calendar.get(Calendar.DATE));
		System.out.println(date.getYear());
		System.out.println(date.getMonth());
		System.out.println(date.getDate());
		System.out.println(date.toString());
	}

	public static Date stringToDate(String strTime, String formatType) {
		Date date = null;
		try {
			SimpleDateFormat formatter = new SimpleDateFormat(formatType);
			date = formatter.parse(strTime);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return date;
	}
}
